<%@page import="java.net.URLEncoder"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.File"%>
<%@page import="databank.DataBank"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="bankVo" class="databank.DataBankVo"/>
<jsp:setProperty property="*" name="bankVo"/>
<%
DataBank bank = new DataBank();
String savePath = bank.getUploadPath();
ServletContext content = this.getServletContext();
String sFilePath = savePath+"/"+bankVo.getFilename();

//파일을 읽기위한 버퍼정의
byte[] b = new byte[4096];
File file = new File(sFilePath);
FileInputStream in = new FileInputStream(sFilePath);

//클라이언트의 요청에 따른 응답정보 세팅
String mineType = getServletContext().getMimeType(sFilePath);
if(mineType == null) mineType = "application/octect-stream";
response.setContentType(mineType);

//한글파일명 처리
String encoding="";

if((request.getHeader("User-Agent").indexOf("Firefox"))>-1){
	String temp = bankVo.getFilename().replace(" ", "");
	encoding = new String(temp.getBytes("UTF-8"), "8859_1");
}else{//IE, Chrome, Opera
	encoding = URLEncoder.encode(bankVo.getFilename(), "UTF-8");
	encoding = encoding.replace("+","%20");
}


//다운로드 다이얼로그창 표시
response.setHeader("Content-Disposition", "attachment;filename="+encoding);

//getOutputStream() 오류방지(더블클릭시도 예방)
out.clear();
out=pageContext.pushBody();

//지정된 경로에 파일저장
ServletOutputStream sos = response.getOutputStream();
int read=0;
while((read = in.read(b, 0, b.length))!=-1){
	sos.write(b,0,read);
}
sos.flush();
sos.close();
in.close();

%>
</body>
</html>